package com.conteudoaberto.framework.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import com.conteudoaberto.framework.exception.SistemaException;



public class Util {

	private static final String ARQUIVO_PROPERTIES = "sistema.properties";

	private static Util instance;
	private Properties properties;

	public static Util getInstance() {
		if (instance == null) {
			instance = new Util();
		}
		return instance;
	}

	private Util() {
		// singleton
	}

	private Properties getArquivoProperties() throws SistemaException {
		if (this.properties == null) {
			try {
				FileInputStream f = new FileInputStream(new File(
						ARQUIVO_PROPERTIES));
				this.properties = new Properties();
				this.properties.load(f);
			} catch (FileNotFoundException e) {
				this.properties = null;
				e.printStackTrace();
				throw new SistemaException(e);
			} catch (IOException e) {
				this.properties = null;
				e.printStackTrace();
				throw new SistemaException(e);
			}
		}
		return this.properties;
	}

	public String getPropriedade(String prop) throws SistemaException {
		return getArquivoProperties().getProperty(prop);
	}
}